package com.tjetc;

import com.tjetc.dao.BankDao;
import com.tjetc.dao.IdCardDao;
import com.tjetc.dao.PersonDao;
import com.tjetc.pojo.Bank;
import com.tjetc.pojo.one.IdCard;
import com.tjetc.pojo.one.Person;
import com.tjetc.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author gaoyongxiang
 * @version v1.0
 * @date 2025/8/19
 */
public class _4OneToOne {

    // 测试单查
    @Test
    public void testTraditional() {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        PersonDao personDao = sqlSession.getMapper(PersonDao.class);
        IdCardDao idCardDao = sqlSession.getMapper(IdCardDao.class);
        Person person = personDao.selectPersonById(1);
        IdCard idCard = idCardDao.selectIdCardById(person.getCardId());
        person.setIdCard(idCard);
        System.out.println(person);
    }

    // 测试mybatis的一对一映射
    @Test
    public void testOneToOne() {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        PersonDao personDao = sqlSession.getMapper(PersonDao.class);
        Person person = personDao.selectPersonById1(1);
        System.out.println(person);
    }


    // 测试嵌套查询
    @Test
    public void testSelect() {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        PersonDao personDao = sqlSession.getMapper(PersonDao.class);
        Person person = personDao.selectPersonById1(1);
        System.out.println(person);
    }




}